package com.runda.partypolicy.app.page.fragment.home;


import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kanade.treeadapter.TreeAdapter;
import com.runda.partypolicy.R;
import com.runda.partypolicy.app.base.BaseFragment;
import com.runda.partypolicy.app.page.viewmodel.ViewModel_Main_AddressBook;
import com.runda.partypolicy.app.repository.bean.CurrentNode;


import java.util.ArrayList;
import java.util.List;

import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * author:  RD_YH
 * date:    2019/4/17
 * version: v1.0
 * description:
 */
public class Fragment_Main_AddressBook extends BaseFragment<ViewModel_Main_AddressBook> {

    @BindView(R.id.commen_title_back)
    ImageView commenTitleBack;
    @BindView(R.id.commen_title_name)
    TextView commenTitleName;
    @BindView(R.id.commen_title_img)
    ImageView commenTitleImg;
    @BindView(R.id.commen_title_start)
    ImageView commenTitleStart;
    @BindView(R.id.commen_search_img)
    ImageView commenSearchImg;
    @BindView(R.id.recycler_two)
    RecyclerView recyclerTwo;
    Unbinder unbinder;
    private List<CurrentNode> list;
    private List<CurrentNode> list1;


    public Fragment_Main_AddressBook() {
    }

    @Override
    public int getLayout() {
        return R.layout.fragment_address_list;
    }

    public static Fragment_Main_AddressBook newInstance() {

        Bundle args = new Bundle();

        Fragment_Main_AddressBook fragment = new Fragment_Main_AddressBook();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public ViewModel_Main_AddressBook initViewModel() {
        return ViewModelProviders.of(this, getViewModelFactory()).get(ViewModel_Main_AddressBook.class);
    }

    @Override
    public void initEvents() {
        commenTitleName.setText("通讯录");
        commenSearchImg.setVisibility(View.VISIBLE);
    }

    @Override
    public void start() {
        init();
    }

    private void init() {
        list = new ArrayList<>();
        list1 = new ArrayList<>();
        //第一级
        CurrentNode currentNode = new CurrentNode(1, 0, "中共寒亭区委", R.drawable.commen_head1);
        CurrentNode currentNode1 = new CurrentNode(2, 0, "寒亭区人民政府", R.drawable.commen_head2);
        CurrentNode currentNode2 = new CurrentNode(3, 0, "区委部门", R.drawable.commen_head3);
        CurrentNode currentNode3 = new CurrentNode(4, 0, "区政府部门", R.drawable.commen_head4);
        CurrentNode currentNode13 = new CurrentNode(5, 0, "街道、开发区", R.drawable.commen_head5);
        list.add(currentNode);
        list.add(currentNode1);
        list.add(currentNode2);
        list.add(currentNode3);
        list.add(currentNode13);
        //第二级别
        CurrentNode currentNode4 = new CurrentNode(6, 1, "李兰祥", R.drawable.tree_2);
        CurrentNode currentNode5 = new CurrentNode(7, 1, "刘金国", R.drawable.tree_04);
        CurrentNode currentNode6 = new CurrentNode(8, 2, "刘金国", R.drawable.tree_2);
        CurrentNode currentNode7 = new CurrentNode(9, 2, "李培进", R.drawable.tree_04);
        CurrentNode currentNode9 = new CurrentNode(10, 3, "区委办公室", R.drawable.tree_04);
        CurrentNode currentNode10 = new CurrentNode(11, 4, "区政府办公室", R.drawable.tree_04);
        CurrentNode currentNode11 = new CurrentNode(12, 5, "寒亭街道", R.drawable.tree_04);
        list.add(currentNode4);
        list.add(currentNode5);
        list.add(currentNode6);
        list.add(currentNode7);
        list.add(currentNode9);
        list.add(currentNode10);
        list.add(currentNode11);

        recyclerTwo.setLayoutManager(new LinearLayoutManager(getActivity()));
        final TreeAdapter<CurrentNode> adapter = new TreeAdapter<>(getActivity());
        adapter.setNodes(list);

        recyclerTwo.setAdapter(adapter);
    }

    @Override
    public void initNotSignEvent() {

    }

    @Override
    public void initNoNetworkEvent() {

    }

    @Override
    public void initShowMessageEvent() {

    }

    @Override
    public void initTokenOverTimeEvent() {

    }

    @Override
    public void initShowOrDismissWaitingEvent() {

    }

    @Override
    public void initStateLayoutEvent() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
